import { useEffect, useState } from 'react';
import { message } from 'antd';
import { fetchMailInfo } from '@/services/mail';

// 收件箱邮件列表
const useMailInfo = query => {
    const [loading, setLoading] = useState(false);
    const [resData, setResData] = useState([]);

    const fetchData = async () => {
        setLoading(true);
        const { data, code, msg } = await fetchMailInfo(query);
        if (code === 10000) {
            setResData(data);
        } else if (msg && msg.length > 0) {
            message.error(msg);
        }
        setLoading(false);
    };
    useEffect(() => {
        if (query && query.mailId !== null) {
            fetchData();
        }
    }, [query]);
    return [loading, resData];
};

export default useMailInfo;
